package mpcs.model
{
	import mpcs.NotiConst;
	import mpcs.model.vo.GlobalVO;
	import mpcs.model.vo.UserVO;
	import mpcs.mylibs.data.SimpleCmd;
	import mpcs.mylibs.data.SimpleMsg;
	import mpcs.mylibs.events.GenericEvent;
	import mpcs.mylibs.interfaces.IConnection;
	import mpcs.mylibs.manager.ConManager;
	
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	public class RegProxy extends Proxy {
		
		public static const NAME:String = "RegProxy";
		
		private var con:IConnection = ConManager.connection;
		
		public function RegProxy() {
			super(NAME);
			
			con.addEventListener("500101", rRegHandle);
		}
		
		// 客户注册请求处理
		public function sRegHandle(uservo:UserVO):void{
			trace("LoginProxy ...  sLogin ... " + uservo.toString());
			var cmd:SimpleCmd = new SimpleCmd(100101);
			cmd.writeString(uservo.getEmail());
			cmd.writeString(uservo.getPassword());
			con.send(cmd);
		}
		
		// 客户注册请求返回
		private function rRegHandle(evt:GenericEvent):void {
			
			var msg:SimpleMsg = evt.getMsg() as SimpleMsg;
			
			if(msg.getHeadData(1) == 0) {
				sendNotification(NotiConst.R_REGISTER_SUCCESS);	
				trace("NotiConst.R_REGISTER_SUCCESS ... rRegHandle ... RegProxy ... ");
				
				con.removeEventListener("500101", rRegHandle);
			}else{
				sendNotification(NotiConst.R_REGISTER_FAILED, msg.getHeadDatas());
				trace("NotiConst.R_REGISTER_FAILED ... rRegHandle ... RegProxy ... ");
			}
			GlobalVO.mpcsApp.regForm.btn_register.enabled = true;
		}
		
	}
}